<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('员工绩效情况新增及修改')"/>
    <th:block th:include="include :: businessCSS"/>
    <style>
        .main-content{background-color: #fff;}
        .gridtable{width: 100%;}
        table.gridtable {
            font-family: verdana,arial,sans-serif;
            font-size:11px;
            color:#333333;
            border-width: 1px;
            border-color: #ddd;
            border-collapse: collapse;
        }
        table.gridtable th {
            border-width: 1px;
            padding: 8px 0;
            border-style: solid;
            border-color: #ddd;
            background-color: #e6e6e6;
        }
        table.gridtable td {
            border-width: 1px;
            padding: 8px 5px;
            border-style: solid;
            border-color: #ddd;
            background-color: #f6f6f6;
            text-align: center;
        }
        .gridtable input{width: 100%;border: none;}
        .hqdata{text-align: right;margin-bottom: 15px;}
        .hqdata span{background: #67b7f5;color: #fff;padding: 5px 10px;border-radius: 10px;cursor: pointer;}




    </style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
    <div class="main-content">
        <form class="layui-form head-form">
            <div class="north">
                <!-- <th:block th:include="include :: business_btn"/> -->
                <th:block th:include="include :: business_tpl('top')"/>
            </div>
            <div style="padding: 20px;height: 80vh;overflow: auto;">
                <div class="hqdata"><span onclick="obtain()">调入数据</span></div>
                <table class="gridtable" >
                    <thead>
                        <tr>
                            <th>员工姓名</th><th>员工岗位</th><th>员工部门</th><th>绩效考核分数</th><th>岗位职责</th><th>岗位权重</th><th>岗位KPI</th>
                            <th>KPI标准</th><th>KPI公式</th><th>结果定义</th><th>KPI实际</th><th>提奖项目</th><th>提奖取值</th><th>提奖系数</th><th>提奖数值</th><th>提奖金额</th>
                        </tr>
                    </thead>
                    
                    <tbody class="tablebody" id="lawtable">
                        <tr><td colspan="16">暂无数据</td></tr>
                    </tbody>
                </table>
            </div>
            <div>
                <div style="height:50px"></div>
                <div class="south" style="height: 50px;z-index: 999;position: fixed;background: #fff;bottom: 0;width: 100%;box-shadow: 0px -10px 10px -10px rgba(0,0,0,0.1);display: flex;align-items: center;justify-content: center;">
                    <button type="button" lay-submit lay-filter="btn-add" class="layui-btn layui-btn-normal">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: businessJS"/>
<th:block th:include="include :: businessTableBtn"/>
<th:block th:include="include :: inlineJS"/>
<script th:inline="javascript">
    var tableData=[[${list}]]
    var fieldsList =[[${fieldsList}]]?[[${fieldsList}]]:[]//表头字段
</script>
<script type="text/javascript">

    var $, layer, form, laydate, element;//定义layui模块
    var nid = $("#nid").val(),noTable;//定义全局参数
    layui.use(['laydate', 'table', 'form', 'layer', 'jquery', 'util', 'element'], function () {
        $ = layui.$, layer = layui.layer, form = layui.form, laydate = layui.laydate, util = layui.util, element = layui.element;
        beforeInit();//表单初始化之前的动作集合
        layui.element.render();
        $.get("/hr/userperformancecondition/listbynid?nid=" + nid, function (res) {
            noTable=res.data;
        });
        layui.element.render();
 
        // xrtable()
        
        // $('#test').focus();
        window.obtain=function(){

            var gUser=$('#gUser').val()
            var fKhYf=$('#fKhYf').val()
            if(gUser && fKhYf){
                $.get("/hr/userperformancecondition/userList",{fKhYf,userID:gUser,nid:nid},function(res){
                    if(res.code==0)xrtable(res.data)
                });
            }else{
                layer.msg('请填写必填项')
            }
        }

        window.xrtable=function(tableData){
            var str=''
            tableData.map((v,i)=>{
                if(v.userPerformanceConditionList.length>0){
                    v.userPerformanceConditionList.map((n,m)=>{
                        if(m==0){
                            str+=`<tr><td rowspan="${v.userPerformanceConditionList.length}">${v.fName ?v.fName :''}</td><td rowspan="${v.userPerformanceConditionList.length}">${v.fGw ?v.fGw :''}</td><td rowspan="${v.userPerformanceConditionList.length}">${v.fBm ?v.fBm :''}</td>
                            <td class="fJxKhFs">${n.fJxKhFs ?n.fJxKhFs :''}</td><td>${n.fKhXm ?n.fKhXm :''}</td><td class="fKhZb">${n.fKhZb ?n.fKhZb :''}</td><td>${n.fKhNr ?n.fKhNr :''}</td><td class="fKhBz">${n.fKhBz ?n.fKhBz :''}</td><td>${n.fKhGs ?n.fKhGs :''}</td><td>${n.fKhJg ?n.fKhJg :''}</td><td><input type="text" class="fJxKhSz" value="${n.fJxKhSz ?n.fJxKhSz :''}"/></td><td>${n.fTjXm ?n.fTjXm :''}</td>
                            <td rowspan="${v.userPerformanceConditionList.length}">${n.fTjQz ?n.fTjQz :''}</td><td class="fTjXs" rowspan="${v.userPerformanceConditionList.length}">${n.fTjXs ?n.fTjXs :''}</td><td class="tdsz" rowspan="${v.userPerformanceConditionList.length}"><input class="fTjSz" type="text" value="${n.fTjSz ?n.fTjSz :''}"/></td><td class="fTjJe" rowspan="${v.userPerformanceConditionList.length}">${n.fTjJe ?n.fTjJe :''}</td>
                            <td style="display:none;" rowspan="${v.userPerformanceConditionList.length}">${v.fUser ?v.fUser :''}</td><td style="display:none;">${n.fKhID ?n.fKhID :''}</td><td style="display:none;">${n.guid ?n.guid :''}</td></tr>`
                        }else{
                            str+=`<tr><td class="fJxKhFs">${n.fJxKhFs ?n.fJxKhFs :''}</td><td>${n.fKhXm ?n.fKhXm :''}</td><td class="fKhZb">${n.fKhZb ?n.fKhZb :''}</td><td>${n.fKhNr ?n.fKhNr :''}</td><td class="fKhBz">${n.fKhBz ?n.fKhBz :''}</td><td>${n.fKhGs ?n.fKhGs :''}</td><td>${n.fKhJg ?n.fKhJg :''}</td><td><input type="text" class="fJxKhSz" value="${n.fJxKhSz ?n.fJxKhSz :''}"/></td><td>${n.fTjXm ?n.fTjXm :''}</td><td style="display:none;">${n.fKhID ?n.fKhID :''}</td><td style="display:none;">${n.guid ?n.guid :''}</td></tr>`
                        }
                    })
                }
                // {
                //     str+=`<tr><td>${v.fName ?v.fName :''}</td><td>${v.fGw ?v.fGw :''}</td><td>${v.fBm ?v.fBm :''}</td>
                //             <td class="fJxKhFs"></td><td></td><td class="fKhZb"></td><td></td><td class="fKhBz"></td><td></td><td></td><td><input type="text" class="fJxKhSz" value=""/></td><td></td>
                //             <td></td><td class="fTjXs"></td><td><input class="fTjSz" type="text" value=""/></td><td class="fTjJe"></td>
                //             <td style="display:none;">${v.fUser ?v.fUser :''}</td><td style="display:none;">${v.fKhID ?v.fKhID :''}</td></tr>`
                // }
            })
            $('.tablebody').html(str)
            $('.fJxKhSz').parent().attr('style','background:#fff;')
            $('.fTjSz').parent().attr('style','background:#fff;')
        }


        $(document).ready(function(){
            var date = new Date();
            var month=formatTime(date)
            $('#fKhYf').val(month)
            if($('#nid').val()){
                var gUser=$('#gUser').val()
                var fKhYf=$('#fKhYf').val()
                if(gUser && fKhYf){
                    $.get("/hr/userperformancecondition/userList",{fKhYf,userID:gUser,nid:nid},function(res){
                        if(res.code==0)xrtable(res.data)
                    });
                }
            }

            $('body').on('click','.tdsz',function(){
                $(this).children('input').focus();
            })
            $('body').on('blur','.fTjSz',function(){
                var tjsz=$(this).val()
                var tjxs=$(this).parent().siblings('.fTjXs').text()
                var tjje=(+tjsz)*(+tjxs)
                $(this).parent().siblings('.fTjJe').text(tjje.toFixed(2))
            })
            $('body').on('blur','.fJxKhSz',function(){
                var sjnum=+$(this).val()
                var bznum=+$(this).parent().siblings('.fKhBz').text()
                var qznum=+$(this).parent().siblings('.fKhZb').text()
                var khfs=""
                if((sjnum/bznum)>1){
                    khfs=1
                }else{
                    khfs=sjnum/bznum
                }
                khfs=khfs*qznum
                var tjxs=$(this).parent().siblings('.fJxKhFs').text(khfs.toFixed(2))

            })
        })

        


        


        

           
        // 保存
		form.on('submit(btn-add)', function(data){
            var is_return = false//是否中断保存
            fieldsList.map((v,i)=>{
                if(v.fieldFrontRequired){
                    if(!$('#'+v.fields).val()){
                         layer.msg(v.fieldName+'不能为空')
                         is_return=true
                    }
                }
            })
            if(is_return) return;
            var lawtable = document.getElementById("lawtable");//获取所有的table
            var rows = lawtable.rows;//获取所有行
            var tabledata=[]
            for(var i=0; i < rows.length; i++){
                var row = rows[i];//获取每一行
                var obj={}
                var a=$('tbody tr').eq(i).children().children('.fJxKhSz').val()
                if(row.cells.length>15){
                    var b=$('tbody tr').eq(i).children().children('.fTjSz').val()
                    obj={'fName':row.cells[0].innerText,'fGw':row.cells[1].innerText,'fBm':row.cells[2].innerText,'fJxKhFs':row.cells[3].innerText,'fKhXm':row.cells[4].innerText,'fKhZb':row.cells[5].innerText,'fKhNr':row.cells[6].innerText,'fKhBz':row.cells[7].innerText,'fKhGs':row.cells[8].innerText,'fKhJg':row.cells[9].innerText,'fJxKhSz':a,'fTjXm':row.cells[11].innerText,'fTjQz':row.cells[12].innerText,'fTjXs':row.cells[13].innerText,'fTjSz':b,'fTjJe':row.cells[15].innerText,'fUser':row.cells[16].innerText,'fKhID':row.cells[17].innerText,'guid':row.cells[18].innerText}
                }else{
                    obj={'fName':tabledata[i-1].fName,'fGw':tabledata[i-1].fGw,'fBm':tabledata[i-1].fBm,'fJxKhFs':row.cells[0].innerText,'fKhXm':row.cells[1].innerText,'fKhZb':row.cells[2].innerText,'fKhNr':row.cells[3].innerText,'fKhBz':row.cells[4].innerText,'fKhGs':row.cells[5].innerText,'fKhJg':row.cells[6].innerText,'fJxKhSz':a,'fTjXm':row.cells[8].innerText,'fTjQz':tabledata[i-1].fTjQz,'fTjXs':tabledata[i-1].fTjXs,'fTjSz':tabledata[i-1].fTjSz,'fTjJe':tabledata[i-1].fTjJe,'fUser':tabledata[i-1].fUser,'fKhID':row.cells[9].innerText,'guid':row.cells[10].innerText}
                }
                tabledata.push(obj)
            }

            $.post("/hr/userperformancecondition/editpost",{infoItems:JSON.stringify(tabledata),infoMap:JSON.stringify(data.field)},function(res){
                layer.msg(res.msg);
                if(res.code==0){
                    window.location.href = "/hr/userperformancecondition/edit?nid="+res.data;
                }
            });
       });
    })


</script>
</body>